<!--用户信息修改的弹窗-->
<template>
    <el-dialog :title="title" :visible.sync="detailVisible" width="35%">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="">
                <el-input v-model="formInline.user" placeholder="请输入您修改后的内容"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">确认修改</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
    export default {
        name: "ModifyUserInformation",
        data(){
            return{
                detailVisible:false,
                title:'',
                value:'',
                initial:'',
                formInline: {
                    user: '',
                }
            }
        },
        methods:{
            //3.定义一个init函数，通过设置detailVisible值为true来让弹窗弹出，这个函数会在父组件的方法中被调用
            init(data,user){
                this.title = data;
                this.formInline.user=user;
                this.detailVisible=true;
                this.initial = user;
                // //data是父组件弹窗传递过来的值，我们可以打印看看
                // console.log(data);
            },
            async onSubmit() {
                if (this.title == "修改名称"){
                    if (this.initial == this.formInline.user) {
                        this.$message({type:'info',message:'您还没有修改内容'})
                    }else if (this.formInline.user == '') {
                        this.$message({type:'info',message:'名称不可以为空'})
                    }
                    else {
                        let res = await this.$http.get('ModifyName', {params: {name:this.formInline.user}});
                        if (res.data.xiuGaiJieGuo == true) {
                            this.$message({type:'success',message:'修改成功'})
                            this.detailVisible=false;
                        }else {
                            this.$message({type:'info',message:'修改失败'})
                        }
                    }

                }else if (this.title == "修改签名") {
                    if (this.initial == this.formInline.user) {
                        this.$message({type:'info',message:'您还没有修改内容'})
                    }
                    // else if (this.formInline.user == '') {
                    //     this.$message({type:'info',message:'名称不可以为空'})
                    // }
                    else {
                        if (this.formInline.user.length > 26) {
                            this.$message.error("长度不可以超过26哦");
                        }else {
                            let res = await this.$http.get('modifyPersonalSignature', {params: {freestyle:this.formInline.user}});
                            if (res.data.xiuGaiJieGuo == true) {
                                this.$message({type:'success',message:'修改成功'})
                                this.detailVisible=false;
                            }else {
                                this.$message({type:'info',message:'修改失败'})
                            }
                        }
                    }
                }else if (this.title == "修改手机号码") {
                    if (this.initial == this.formInline.user) {
                        this.$message({type:'info',message:'您还没有修改内容'})
                    }else if (this.formInline.user == '') {
                        this.$message({type:'info',message:'号码不可以为空'})
                    }else {
                        let reg = /^1[0-9]{10}$/
                        if(!reg.test(this.formInline.user)){
                            this.$message.error('请输入正确的手机号!');
                        }else {
                            let res = await this.$http.get('modifyPhone', {params: {phone:this.formInline.user}});
                            if (res.data.xiuGaiJieGuo == true) {
                                this.$message({type:'success',message:'修改成功'})
                                this.detailVisible=false;
                            }else {
                                this.$message({type:'info',message:'修改失败'})
                            }
                        }

                    }
                }else if (this.title == "修改邮箱地址") {
                    if (this.initial == this.formInline.user) {
                        this.$message({type:'info',message:'您还没有修改内容'})
                    }else if (this.formInline.user == '') {
                        this.$message({type:'info',message:'邮箱地址不可以为空'})
                    }
                    else {
                        let tr = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
                        if (!tr.test(this.formInline.user)) {
                            this.$message.error("请输入正确的邮箱");
                        }else {
                            let res = await this.$http.get('modifyEmail', {params: {email:this.formInline.user}});
                            if (res.data.xiuGaiJieGuo == true) {
                                this.$message({type:'success',message:'修改成功'})
                                this.detailVisible=false;
                            }else {
                                this.$message({type:'info',message:'修改失败'})
                            }
                        }

                    }
                }else if (this.title == "修改密码"){
                    if (this.initial == this.formInline.user) {
                        this.$message({type:'info',message:'您还没有修改内容'})
                    }else if (this.formInline.user == '') {
                        this.$message({type:'info',message:'密码不可以为空'})
                    }
                    else {
                        let res = await this.$http.get('modifyPassword', {params: {password:this.formInline.user}});
                        if (res.data.xiuGaiJieGuo == true) {
                            this.$message({type:'success',message:'修改成功'})
                            this.detailVisible=false;
                        }else {
                            this.$message({type:'info',message:'修改失败'})
                        }
                    }

                }
            }
        }
    }
</script>

<style scoped>

</style>